package src.main.shengchengqi;

//定义n个生成器Builder类，生产不同产品
public interface IBuild
{
    public void createUnit1();
    public void createUnit2();
    public void createUnit3();
    public Product composite();
    public Product create();
}
//产品1
class BuildProduct implements IBuild
{
    Product p = new Product();
    @Override
    public void createUnit1(){
      Unit1 unit1= new Unit1();
      unit1.setU1("产品1组件1");
      p.setUnit1(unit1);
    }

    @Override
    public void createUnit2() {
        Unit2 unit2=new Unit2();
        unit2.setU2("产品1组件2");
        p.setUnit2(unit2);
    }

    @Override
    public void createUnit3() {
        Unit3 unit3=new Unit3();
        unit3.setU3("产品1组件3");
        p.setUnit3(unit3);
    }

    @Override
    public Product composite() {
        createUnit1();
        createUnit2();
        createUnit3();
        System.out.println(p.toString());
        return p;
    }

    public Product create(){
        return composite();      }

}

class BuildProduct1 implements IBuild
{
    Product p = new Product();
    @Override
    public void createUnit1(){
        Unit1 unit1= new Unit1();
        unit1.setU1("产品2组件1");
        p.setUnit1(unit1);
    }

    @Override
    public void createUnit2() {
        Unit2 unit2=new Unit2();
        unit2.setU2("产品2组件2");
        p.setUnit2(unit2);
    }

    @Override
    public void createUnit3() {
        Unit3 unit3=new Unit3();
        unit3.setU3("产品2组件3");
        p.setUnit3(unit3);
    }

    @Override
    public Product composite() {
        createUnit1();
        createUnit2();
        createUnit3();
        System.out.println(p.toString());
        return p;
    }

    public Product create(){ return composite();  }

}